package cn.schoolwow.quickdao.module.database.dml.instance.service.save;

import cn.schoolwow.quickdao.module.database.dml.existQuery.service.GetInstanceCountFlow;
import cn.schoolwow.quickdao.module.database.dml.instance.service.insert.InsertInstanceCompositeBusiness;
import cn.schoolwow.quickdao.module.database.dml.instance.service.update.UpdateInstanceCompositeBusiness;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

public class SaveInstanceFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        flowContext.executeFlowList(new GetInstanceCountFlow());
        Long count = flowContext.getData("count", Long.class);
        if(null==count||count==0){
            flowContext.executeCompositeFlowList(new InsertInstanceCompositeBusiness());
        }else{
            flowContext.executeCompositeFlowList(new UpdateInstanceCompositeBusiness());
        }
    }

    @Override
    public String name() {
        return "保存实例";
    }
}
